package com.hskn.hss.module.jobset.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hskn.hss.core.utils.LoginUtils;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.jobset.entity.Jobset;
import com.hskn.hss.module.jobset.mapper.JobsetMapper;
import com.hskn.hss.module.jobset.service.IJobsetService;
import com.hskn.hss.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hskn
 * @since 2021-05-11
 */
@Service
public class JobsetServiceImpl extends ServiceImpl<JobsetMapper, Jobset> implements IJobsetService {

    @Resource
    private JobsetMapper jobsetMapper;

    @Override
    public void mUpdate(JSONObject params) throws HssException {

        String uid = LoginUtils.getUser().getUid();
        if (StringUtils.isEmpty(params) || StringUtils.isEmpty(params.getString("jobsetId"))) {
            throw new HssException("参数错误");
        }
        Jobset jobset = JSON.parseObject(params.toJSONString(), Jobset.class);
        jobset.setUpdateUid(uid);
        jobsetMapper.updateById(jobset);
    }

    @Override
    public Jobset detail(JSONObject params) throws HssException {
        String jobsetId = params.getString("jobsetId");
        Jobset jobset = jobsetMapper.selectById(jobsetId);
        return jobset;
    }
}
